package com.design.patterns.list.iterator;

import com.design.patterns.list.iterator.aggregate.College;
import com.design.patterns.list.iterator.aggregate.Department;

import java.util.Iterator;
import java.util.List;

/**
 * @author Wangzhiwen
 */
public class CollegeOut {

    private List<College> colleges;

    public CollegeOut(List<College> colleges) {
        this.colleges = colleges;
    }

    public void printCollegeInfo(){
        // List 实现的迭代器
        Iterator<College> collegeIterator = colleges.iterator();
        while (collegeIterator.hasNext()){
            College college = collegeIterator.next();
            Iterator<Department> departmentIterator = college.createIterator();
            printDepartment(departmentIterator);
        }
    }

    public void printDepartment(Iterator<Department> departmentIterator){
        while (departmentIterator.hasNext()){
            Department department = departmentIterator.next();
            System.out.println(department);
        }
    }
}
